//package com.iotechn.unimall.app.quartz;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.mapper.EntityWrapper;
//import com.baomidou.mybatisplus.mapper.Wrapper;
//import com.iotechn.unimall.biz.service.address.AddressBizService;
//import com.iotechn.unimall.biz.service.colonel.ColonelBizService;
//import com.iotechn.unimall.biz.service.distribution.DistributionBizService;
//import com.iotechn.unimall.biz.service.goods.GoodsBizService;
//import com.iotechn.unimall.biz.service.goods.GoodsStockCollectService;
//import com.iotechn.unimall.biz.service.order.OrderBizService;
//import com.iotechn.unimall.biz.service.orderlog.OrderLogBizService;
//import com.iotechn.unimall.biz.service.ordertype.OrderTypeBizService;
//import com.iotechn.unimall.biz.service.seckill.SeckillSkuBizService;
//import com.iotechn.unimall.core.exception.AdminServiceException;
//import com.iotechn.unimall.core.exception.ExceptionDefinition;
//import com.iotechn.unimall.core.util.DateUtils;
//import com.iotechn.unimall.core.util.EmotionalAnalysis;
//import com.iotechn.unimall.data.component.LockComponent;
//import com.iotechn.unimall.data.domain.*;
//import com.iotechn.unimall.data.enums.*;
//import com.iotechn.unimall.data.mapper.*;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.TransactionStatus;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.transaction.support.TransactionCallbackWithoutResult;
//import org.springframework.transaction.support.TransactionTemplate;
//import org.springframework.util.CollectionUtils;
//import org.springframework.util.StringUtils;
//
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * Created by rize on 2019/7/21.
// */
//@Component
//@EnableScheduling
//public class Check_1 {
//
//    private static final Logger logger = LoggerFactory.getLogger(CheckQuartz.class);
//    private static final String ORDER_STATUS_LOCK = "ORDER_STATUS_QUARTZ_LOCK";
//    private static final String GROUP_SHOP_START_LOCK = "GROUP_SHOP_START_LOCK";
//    private static final String GROUP_SHOP_END_LOCK = "GROUP_SHOP_END_LOCK";
//    private static final String GROUP_SHOP_LOCK_LOCK = "GROUP_SHOP_LOCK_LOCK";
//    @Autowired
//    CollectMapper collectMapper;
//    @Autowired
//    SeckillSkuMapper seckillSkuMapper;
//    @Autowired
//    SeckillSkuBizService seckillSkuBizService;
//    @Autowired
//    private OrderMapper orderMapper;
//    @Autowired
//    private OrderBizService orderBizService;
//    @Autowired
//    private GroupShopMapper groupShopMapper;
//    @Autowired
//    private DistributionBizService distributionBizService;
//    @Autowired
//    private ColonelBizService colonelBizServicec;
//    @Autowired
//    private SpuMapper spuMapper;
//    @Autowired
//    private SkuMapper skuMapper;
//    @Autowired
//    private OrderSkuMapper orderSkuMapper;
//    @Autowired
//    private LockComponent lockComponent;
//    @Autowired
//    private TransactionTemplate transactionTemplate;
//    @Autowired
//    private SeckillSpuMapper seckillSpuMapper;
//    @Autowired
//    private GoodsStockCollectService goodsStockCollectService;
//
//    @Autowired
//    private GoodsBizService goodsBizService;
//
//    @Autowired
//    private SeckillOrderSkuMapper seckillOrderSkuMapper;
//    @Autowired
//    private OrderTypeBizService orderTypeBizService;
//
//    @Autowired
//    private OrderLogBizService orderLogBizService;
//
//    @Autowired
//    private AddressBizService addressBizService;
//
//    @Autowired
//    private AddressDivisionMapper addressDivisionMapper;
//    @Autowired
//    private AppraiseMapper appraiseMapper;
//    /*
//
//     */
//    /**
//     * 跑一次数据处理历史佣金没有解冻的问题
//     *//*
//
//    @Scheduled(cron = "10 * * * * ?")
//    @Transactional(rollbackFor = Exception.class)
//    public void helpStart() throws Exception {
//        List<OrderDO> waitConfirmNos = orderMapper.selectExpireOrderNos_help();
//        waitConfirmNos.forEach(item -> {
//            transactionTemplate.execute(new TransactionCallbackWithoutResult() {
//                @Override
//                protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
//
//                try{
//                    if (item.getDistributionId() != null) {
//                        logger.info("开始正式发放");
//                        distributionBizService.unfreezeOrder_help(item.getOrderNo());
//                    }
//
//                } catch (Exception e) {
//                    logger.error("[订单状态检测定时任务] 异常", e);
//                } finally {
//                    lockComponent.release(ORDER_STATUS_LOCK);
//                }
//
//                }
//            });
//        });
//
//
//    }
//
//*/
//    @Autowired
//    private GroupBarginUserMapper groupBarginUserMapper;
//    @Autowired
//    private GroupBarginMapper groupBarginMapper;
//
//    /**
//     * 订单状态定时轮训
//     */
//    @Scheduled(cron = "0 * * * * ?")
//    public void checkOrderStatus() {
//        if (lockComponent.tryLock(ORDER_STATUS_LOCK, 15)) {
//            try {
//                Date now = new Date();
//                // 请注意，此处并非查出订单的所有信息，若需要其他字段，请自行添加
//                List<OrderDO> nos = orderMapper.selectExpireOrderNos(OrderStatusType.UNPAY.getCode(), new Date(now.getTime() - 1000l * 60 * 15));
//                if (!CollectionUtils.isEmpty(nos)) {
//                    nos.forEach(no -> {
//                        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
//                            @Override
//                            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
//                                try {
//                                    OrderDO updateOrderDO = new OrderDO();
//                                    updateOrderDO.setStatus(OrderStatusType.CANCELED_SYS.getCode());
//                                    updateOrderDO.setGmtUpdate(now);
//                                    List<OrderSkuDO> orderSkuList = orderSkuMapper.selectList(new EntityWrapper<OrderSkuDO>().eq("order_id", no.getId()));
//                                    orderSkuList.forEach(item -> {
//                                        skuMapper.returnSkuStock(item.getSkuId(), item.getNum());
//                                        goodsBizService.returnWarehouseGoodsStock(item.getBarCode(), item.getNum(), no.getOrderNo(), no.getId());
//                                        //秒杀修改秒杀库
//                                        seckillSkuBizService.cannelSeckillSku(no.getOrderNo(), item);
//                                        //取货码
//                                        orderTypeBizService.invalidGetCode(item.getOrderNo());
//                                    });
//                                    Long distributionDeductionId = no.getDistributionDeductionId();
//                                    if (distributionDeductionId != null) {
//                                        // 退还分销用户佣金
//                                        distributionBizService.returnDeduction(distributionDeductionId, null, no.getUserId());
//                                    }
//                                    orderBizService.changeOrderStatus(no.getOrderNo(), OrderStatusType.UNPAY.getCode(), updateOrderDO);
//                                    //添加订单流水
//                                    OrderLogDO orderLogDO = new OrderLogDO();
//                                    orderLogDO.setOrderId(no.getId());
//                                    orderLogDO.setOrderNo(no.getOrderNo());
//                                    orderLogDO.setLastStatus(OrderStatusType.UNPAY.getCode());
//                                    orderLogDO.setCurrentStatus(updateOrderDO.getStatus());
//                                    String detail = JSON.toJSONString(no);
//                                    orderLogDO.setDetail(detail);
//                                    orderLogBizService.addOrderLog(orderLogDO);
//                                } catch (Exception e) {
//                                    logger.error("[未付款检测] 异常", e);
//                                    transactionStatus.setRollbackOnly();
//                                }
//                            }
//                        });
//                    });
//                }
//                //15分钟执行一次
//                long minutes = (now.getTime() / (1000 * 60));
//                if (minutes % 15 == 0) {
//                    logger.info("有一批数据开始发放佣金了");
//                    List<OrderDO> waitConfirmNos = orderMapper.selectExpireOrderNos(OrderStatusType.WAIT_CONFIRM.getCode(), new Date(now.getTime() - 1000l * 60 * 60 * 24 * 3));
//                    waitConfirmNos.forEach(item -> {
//                        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
//                            @Override
//                            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
//                                try {
//                                    OrderDO updateOrderDO = new OrderDO();
//                                    updateOrderDO.setStatus(OrderStatusType.WAIT_APPRAISE.getCode());
//                                    updateOrderDO.setGmtUpdate(now);
//                                    List<OrderSkuDO> orderSkuList = orderSkuMapper.selectList(new EntityWrapper<OrderSkuDO>().eq("order_id", item.getId()));
//                                    orderSkuList.forEach(skuItem -> {
//                                        skuMapper.decSkuFreezeStock(skuItem.getSkuId(), skuItem.getNum());
//                                        goodsBizService.decWarehouseGoodsStock(skuItem.getBarCode(), skuItem.getNum(), item.getOrderNo(), item.getId());
//                                    });
//                                    if (item.getDistributionId() != null) {
//                                        logger.info("开始发放");
//                                        distributionBizService.unfreezeOrder(item.getOrderNo());
//                                    }
//                                    if (item.getColonelId() != null) {
//                                        logger.info("开始给团长发放");
//                                        colonelBizServicec.unfreezeOrder(item.getOrderNo());
//                                    }
//                                    Long distributionDeductionId = item.getDistributionDeductionId();
//                                    if (distributionDeductionId != null) {
//                                        //分销用户抵扣状态完成
//                                        distributionBizService.confirmDeduction(distributionDeductionId, item.getUserId());
//                                    }
//                                    orderBizService.changeOrderStatus(item.getOrderNo(), OrderStatusType.WAIT_CONFIRM.getCode(), updateOrderDO);
//                                    //添加订单流水
//                                    OrderLogDO orderLogDO = new OrderLogDO();
//                                    orderLogDO.setOrderId(item.getId());
//                                    orderLogDO.setOrderNo(item.getOrderNo());
//                                    orderLogDO.setLastStatus(OrderStatusType.WAIT_CONFIRM.getCode());
//                                    orderLogDO.setCurrentStatus(updateOrderDO.getStatus());
//                                    String detail = JSON.toJSONString(updateOrderDO);
//                                    orderLogDO.setDetail(detail);
//                                    orderLogBizService.addOrderLog(orderLogDO);
//                                } catch (Exception e) {
//                                    logger.error("[未确认检测] 异常", e);
//                                    transactionStatus.setRollbackOnly();
//                                }
//                            }
//                        });
//
//                    });
//                }
//            } catch (Exception e) {
//                logger.error("[订单状态检测定时任务] 异常", e);
//            } finally {
//                lockComponent.release(ORDER_STATUS_LOCK);
//            }
//        }
//    }
//
//    /**
//     * 设定60s跑一次, 判断到了团购开始时间的激活一下
//     */
//    @Scheduled(cron = "10 * * * * ?")
//    @Transactional(rollbackFor = Exception.class)
//    public void groupShopStart() throws Exception {
//        if (lockComponent.tryLock(GROUP_SHOP_START_LOCK, 30)) {
//            try {
//                Date now = new Date();
//                /**
//                 * 1. 激活 团购时间开始的活动商品
//                 */
//                // 1.1 查询在活动期间,且冻结状态的团购商品
//                List<GroupShopDO> groupShopDOList = groupShopMapper.selectList(new EntityWrapper<GroupShopDO>()
//                        .le("gmt_start", now).and()
//                        .gt("gmt_end", now).and()
//                        .eq("status", StatusType.LOCK.getCode()));
//                if (groupShopDOList != null) {
//                    for (GroupShopDO groupShopDO : groupShopDOList) {
//                        groupShopDO.setGmtUpdate(now);
//                        groupShopDO.setStatus(StatusType.ACTIVE.getCode());
//                        SpuDO spuDO = spuMapper.selectById(groupShopDO.getSpuId());
//                        if (spuDO == null) {
//                            continue;
//                            // throw new AdminServiceException(ExceptionDefinition.GROUP_SHOP_SPU_NO_EXITS);
//                        }
//
//                        // 1.2 检查商品是不是已经下架
//                        if (spuDO.getStatus().equals(StatusType.ACTIVE.getCode())) {
//                            if (groupShopMapper.updateById(groupShopDO) <= 0) {
//                                throw new AdminServiceException(ExceptionDefinition.GROUP_SHOP_SPU_UPDATE_SQL_QUERY_ERROR);
//                            }
//                        }
//                    }
//                }
//            } catch (Exception e) {
//                logger.error("[团购开始 定时任务] 异常", e);
//                throw e;
//            } finally {
//                lockComponent.release(GROUP_SHOP_START_LOCK);
//            }
//        }
//
//
//    }
//
//    /**
//     * 判断团购结束的情况 将已经有订单的设置为待发货
//     *
//     * @throws Exception
//     */
//    @Scheduled(cron = "10 * * * * ?")
//    @Transactional(rollbackFor = Exception.class)
//    public void groupShopEnd() throws Exception {
//        if (lockComponent.tryLock(GROUP_SHOP_END_LOCK, 30)) {
//            try {
//                Date now = new Date();
//                /**
//                 * 2. 冻结 团购时间结束的活动商品,并根据对应情况处理订单
//                 */
//                Wrapper<GroupShopDO> wrapper = new EntityWrapper<GroupShopDO>()
//                        //.gt("status",StatusType.LOCK.getCode())
//                        .in("status", "1,2")
//                        //.eq("status", StatusType.ACTIVE.getCode())
//                        .andNew()
//                        .gt("gmt_start", now)
//                        .or()
//                        .le("gmt_end", now);
//                List<GroupShopDO> lockGroupShopDOList = groupShopMapper.selectList(wrapper);
//                // 2.2 将团购订单的状态转为对应的退款或待出库状态,对未达人数且自动退款的商品订单进行退款,对达到人数或不自动退款的商品订单转换状态
//                if (!CollectionUtils.isEmpty(lockGroupShopDOList)) {
//                    // 2.1 对过期团购商品冻结
//                    GroupShopDO lockGroupShopDO = new GroupShopDO();
//                    //改成自动下架
//                    // lockGroupShopDO.setStatus(StatusType.LOCK.getCode());
//                    lockGroupShopDO.setStatus(StatusType.AUTOXIAJIA.getCode());
//                    lockGroupShopDO.setGmtUpdate(now);
//                    Wrapper<GroupShopDO> wrapper1 = new EntityWrapper<GroupShopDO>()
//                            //手动下架的不需要调整
//                            .eq("status", StatusType.ACTIVE.getCode())
//                            .andNew()
//                            .gt("gmt_start", now)
//                            .or()
//                            .le("gmt_end", now);
//                    groupShopMapper.update(lockGroupShopDO, wrapper1);
//                    for (GroupShopDO groupShopDO : lockGroupShopDOList) {
//                        // 2.2.1查询团购订单中数据
//                        List<OrderDO> lockOrderList = orderMapper.selectList(
//                                new EntityWrapper<OrderDO>()
//                                        .eq("group_shop_id", groupShopDO.getId())
//                                        .eq("status", OrderStatusType.GROUP_SHOP_WAIT.getCode()));
//
//                        if (CollectionUtils.isEmpty(lockOrderList)) {
//                            continue;
//                        }
//
//                        if (groupShopDO.getAutomaticRefund() == GroupShopAutomaticRefundType.YES.getCode() && groupShopDO.getAlreadyBuyNumber().compareTo(groupShopDO.getMinimumNumber()) < 0) {
//                            // 2.2.2.1.退款
//                            logger.info("[团购结束] 退款逻辑 groupShopId:" + groupShopDO.getId());
//                            for (OrderDO orderDO : lockOrderList) {
//                                transactionTemplate.execute(new TransactionCallbackWithoutResult() {
//
//                                    @Override
//                                    protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
//                                        try {
//                                            //对订单退款保证原子性，仅退款成功的单子，变更状态
//                                            orderBizService.groupShopStatusRefund(orderDO.getOrderNo());
//                                            //添加订单流水
//                                            OrderLogDO orderLogDO = new OrderLogDO();
//                                            orderLogDO.setOrderId(orderDO.getId());
//                                            orderLogDO.setOrderNo(orderDO.getOrderNo());
//                                            orderLogDO.setLastStatus(OrderStatusType.GROUP_SHOP_WAIT.getCode());
//                                            orderLogDO.setCurrentStatus(OrderStatusType.REFUNDED.getCode());
//                                            String detail = JSON.toJSONString(orderDO);
//                                            orderLogDO.setDetail(detail);
//                                            orderLogBizService.addOrderLog(orderLogDO);
//                                            logger.info("[团购订单退款] 完成 orderNo:" + orderDO.getOrderNo());
//                                        } catch (Exception e) {
//                                            logger.error("[团购订单退款] 异常 orderNo:" + orderDO.getOrderNo() + "; errmsg:" + e.getMessage());
//                                            transactionStatus.setRollbackOnly();
//                                        }
//                                    }
//                                });
//                            }
//                        } else {
//                            logger.info("[团购结束] 发货逻辑 groupShopId:" + groupShopDO.getId());
//                            // 2.2.2.2 转换订单为待出货状态 (非自动退款场景)
//                            List<Long> collect = lockOrderList.stream().map(s -> s.getId()).collect(Collectors.toList());
//                            OrderDO orderDO = new OrderDO();
//                            orderDO.setStatus(OrderStatusType.WAIT_STOCK.getCode());
//                            orderMapper.update(orderDO, (
//                                    new EntityWrapper<OrderDO>()
//                                            .in("id", collect)
//                                            .eq("status", OrderStatusType.GROUP_SHOP_WAIT.getCode())));
//
//                            //添加订单流水
//                            OrderLogDO orderLogDO = new OrderLogDO();
//                            orderLogDO.setOrderId(orderDO.getId());
//                            orderLogDO.setOrderNo(orderDO.getOrderNo());
//                            orderLogDO.setLastStatus(OrderStatusType.GROUP_SHOP_WAIT.getCode());
//                            orderLogDO.setCurrentStatus(OrderStatusType.WAIT_STOCK.getCode());
//                            String detail = JSON.toJSONString(orderDO);
//                            orderLogDO.setDetail(detail);
//                            orderLogBizService.addOrderLog(orderLogDO);
//                        }
//                    }
//                }
//            } catch (Exception e) {
//                logger.error("[团购结束 定时任务] 异常", e);
//                throw e;
//            } finally {
//                lockComponent.release(GROUP_SHOP_END_LOCK);
//            }
//        }
//
//    }
//
//    @Scheduled(cron = "10 * * * * ?")
//    @Transactional(rollbackFor = Exception.class)
//    public void groupShopLock() throws Exception {
//        if (lockComponent.tryLock(GROUP_SHOP_LOCK_LOCK, 30)) {
//            try {
//                Date now = new Date();
//                /**
//                 * 3 冻结 团购活动期间却被下架的商品
//                 */
//                EntityWrapper<GroupShopDO> groupShopDOEntityWrapper = new EntityWrapper<>();
//
//                // 3.1 从团购中查询活动期间的商品
//                groupShopDOEntityWrapper.eq("status", StatusType.ACTIVE.getCode())
//                        .and()
//                        .le("gmt_start", now)
//                        .and()
//                        .gt("gmt_end", now);
//                List<GroupShopDO> groupShopDOS = groupShopMapper.selectList(groupShopDOEntityWrapper);
//                if (!CollectionUtils.isEmpty(groupShopDOS)) {
//                    List<Long> spuIdList = groupShopDOS.stream().map(t -> t.getSpuId()).collect(Collectors.toList());
//
//                    // 3.2 在团购中查询给出spuID,是否有被下架的商品
//                    List<SpuDO> spuDOS = spuMapper.selectList(new EntityWrapper<SpuDO>().in("id", spuIdList).eq("status", StatusType.LOCK.getCode()));
//                    if (!CollectionUtils.isEmpty(spuDOS)) {
//                        List<Long> collect = spuDOS.stream().map(t -> t.getId()).collect(Collectors.toList());
//                        GroupShopDO groupShopDO = new GroupShopDO();
//                        groupShopDO.setStatus(StatusType.LOCK.getCode());
//                        groupShopDO.setGmtUpdate(now);
//                        groupShopMapper.update(groupShopDO, (new EntityWrapper<GroupShopDO>().in("spu_id", collect)));
//                    }
//                }
//            } catch (Exception e) {
//                logger.error("[团购锁定 定时任务] 异常", e);
//                throw e;
//            } finally {
//                lockComponent.release(GROUP_SHOP_LOCK_LOCK);
//            }
//        }
//
//    }
//
//    /**
//     * 定时修改收藏列表内的秒杀商品状态
//     *
//     * @param seckillSpuDO
//     */
//    public void checkCollectSku(SeckillSpuDO seckillSpuDO) {
//        //修改收藏列表内的 秒杀商品的状态
//        CollectDO param = new CollectDO();
//        param.setType(CollectType.COLLECTTYPESECKILL.getCode());
//        param.setTypeId(seckillSpuDO.getId());
//        CollectDO collectDO = collectMapper.selectOne(param);
//        collectDO.setType(CollectType.COLLECTTYPEDEFAULT.getCode());
//        collectMapper.update(collectDO, new EntityWrapper<CollectDO>().eq("type_id", seckillSpuDO.getId()).eq("type", CollectType.COLLECTTYPESECKILL.getCode()));
//    }
//
//    @Scheduled(cron = "0 0/1 * * * ? ")
//    @Transactional(rollbackFor = Exception.class)
//    public void seckillLock() throws Exception {
//        logger.info(">>>>>>>>>>>>>>>Seckill  check status  by  time  >>>>>>>>>>>>>>>");
//        List<SeckillSpuDO> seckillSpuDOS = seckillSpuMapper.selectList(new EntityWrapper<SeckillSpuDO>().ne("status", SeckillStatusType.SECKILLSUSPEND.getCode()).ne("status", SeckillStatusType.SECKILLDISMOUNT.getCode()));
//        for (SeckillSpuDO seckillSpuDO : seckillSpuDOS
//        ) {
//            //当前活动状态
//            Integer status = seckillSpuDO.getStatus();
//            Date gmtStart = seckillSpuDO.getGmtStart();
//            Date gmtEnd = seckillSpuDO.getGmtEnd();
//            Date now = new Date();
////            if(seckillSpuDO.getStatus()!= SeckillStatusType.SECKILLSUSPEND.getCode() && seckillSpuDO.getStatus()!= SeckillStatusType.SECKILLDISMOUNT.getCode()){
//            //未开启
//            if (now.before(gmtStart)) {
//                seckillSpuDO.setStatus(SeckillStatusType.BEFORESECKILL.getCode());
//            }
//            //开启秒杀
//            if (now.before(gmtEnd) && now.after(gmtStart)) {
//                seckillSpuDO.setStatus(SeckillStatusType.SECKILLING.getCode());
//                seckillSkuBizService.makeredisCaCheSeckillSkuById(seckillSpuDO.getId());
//            }
//            //结束秒杀
//            if (now.after(gmtEnd)) {
//                seckillSpuDO.setStatus(SeckillStatusType.SECKILLOVER.getCode());
//                seckillSkuBizService.deleteSeckillSku(seckillSpuDO.getId());
//            }
//            seckillSpuMapper.updateById(seckillSpuDO);
////            }
//
//        }
//    }
//
//    @Scheduled(cron = "0 0/5 * * * ? ")
//    public void updateSeckillSkuDO() throws Exception {
//        List<Long> seckillSkuIdList = seckillSkuMapper.getSeckillSkuIdList(null);
//        if (seckillSkuIdList.size() < 1) {
//            return;
//        }
//        for (Long id : seckillSkuIdList
//        ) {
//            SeckillSkuDO seckillSkuDORedis = seckillSkuBizService.getSeckillSkuDORedis(id);
//            if (seckillSkuDORedis != null && seckillSkuDORedis.getId() != null) {
//                seckillSkuMapper.updateById(seckillSkuDORedis);
//            }
//
//        }
//        List<Long> longs = seckillSpuMapper.selectAllSeckillSpuId();
//        for (Long id : longs
//        ) {
//            SeckillSpuDO SeckillSpuDORedis = seckillSkuBizService.getSeckillSpuDORedis(id);
//            if (SeckillSpuDORedis != null && SeckillSpuDORedis.getId() != null) {
//                seckillSpuMapper.updateById(SeckillSpuDORedis);
//            }
//        }
//    }
//
//    //每月月初00:00:00汇总商品库存情况
//    @Scheduled(cron = "0 0 0 1 * ?")
//    public void getOriginalStockByTime() {
//        logger.info("[每月月初汇总商品库存情况]");
//        goodsStockCollectService.getOriginalStockByTime();
//    }
//
//    //每隔10分钟汇总商品库存情况
//    @Scheduled(cron = "0 */10 * * * ?")
//    @Transactional(rollbackFor = Exception.class)
//    public void handleSkuStockCollect() {
//        logger.info("[每隔10分钟汇总商品库存情况]:{}", new Date());
//        goodsStockCollectService.handleSkuStockCollect();
//    }
//
//    //每隔15分钟汇总订单地址情况
//    @Scheduled(cron = "0 */15 * * * ?")
//    @Transactional(rollbackFor = Exception.class)
//    public void handleOrderAddressDivision() {
//        Date now = new Date();
//        logger.info("[每隔15分钟汇总订单地址情况]:{}", now);
//        Long startTime = System.currentTimeMillis();
//        List<AddressDivisionDO> addressDivisionDOS = addressBizService.analysisOrderAddressDivision();
//        for (AddressDivisionDO ad : addressDivisionDOS) {
//            transactionTemplate.execute(new TransactionCallbackWithoutResult() {
//                @Override
//                protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
//                    try {
//                        AddressDivisionDO dbAddressDivisionQuery = new AddressDivisionDO();
//                        dbAddressDivisionQuery.setProvince(ad.getProvince());
//                        dbAddressDivisionQuery.setCity(ad.getCity());
//                        dbAddressDivisionQuery.setDistrict(ad.getDistrict());
//                        dbAddressDivisionQuery.setTown(ad.getTown());
//                        AddressDivisionDO dbAddressDivision = addressDivisionMapper.selectOne(dbAddressDivisionQuery);
//                        List<String> str = new LinkedList<>();
//                        if (!StringUtils.isEmpty(ad.getLastPrimaryKeyList())) {
//                            str = new LinkedList<>(Arrays.asList(ad.getLastPrimaryKeyList().split(",")));
//                        }
//                        if (dbAddressDivision != null) {
//                            dbAddressDivision.setSize(dbAddressDivision.getSize() + ad.getSize());
//                            if (!StringUtils.isEmpty(dbAddressDivision.getLastPrimaryKeyList())) {
//                                List<String> s = new LinkedList<>(Arrays.asList(dbAddressDivision.getLastPrimaryKeyList().split(",")));
//                                str.addAll(s);
//                            }
//                            if (!CollectionUtils.isEmpty(str)) {
//                                str = str.stream().filter(i -> !StringUtils.isEmpty(i)).distinct().sorted((s1, s2) -> Long.valueOf(s2).compareTo(Long.valueOf(s1))).collect(Collectors.toList());
//                                dbAddressDivision.setLastPrimaryKeyList(String.join(",", str));
//                            }
//
//                            dbAddressDivision.setGmtUpdate(now);
//                            addressDivisionMapper.updateById(dbAddressDivision);
//                        } else {
//                            ad.setGmtUpdate(now);
//                            addressDivisionMapper.insert(ad);
//                        }
//                    } catch (Exception e) {
//                        e.printStackTrace();
////                        transactionStatus.setRollbackOnly();
//                    }
//                }
//            });
//        }
//        Long endTime = System.currentTimeMillis();
//        logger.info("汇总订单地址耗时:{}s", (endTime - startTime) / 1000.0f);
//    }
//
//    /**
//     * 每天凌晨两点刷前一天的评论
//     * 定时刷新评论    判断评论情绪
//     */
//    @Scheduled(cron = "0 0 0 2 * ? ")
//    @Transactional(rollbackFor = Exception.class)
//    public void timingGetEmotionalAnalysis() throws Exception {
//        Wrapper<AppraiseDO> wrapper = new EntityWrapper<>();
//        Date startDate = DateUtils.getZeroDate(DateUtils.getBeforeSomeDaysDate(new Date(), -1));
//        Date endDate = DateUtils.getZeroDate(new Date());
//        wrapper.between("gmt_create", startDate, endDate);
//        List<AppraiseDO> appraiseDOS = appraiseMapper.selectList(wrapper);
//        if (appraiseDOS == null || appraiseDOS.size() < 1) {
//            return;
//        }
//        for (AppraiseDO appraiseDO : appraiseDOS
//        ) {
//            String appraise = appraiseDO.getContent();
//            Integer positiveProb = 100;
//            Integer negativeProb = 0;
//            if (!StringUtils.isEmpty(appraise)) {
//                Map<String, String> emotionalAnalysis = EmotionalAnalysis.getEmotionalAnalysis(appraise);
//                Float positive_prob = emotionalAnalysis.get("positive_prob") == null ? 100f : Float.parseFloat(emotionalAnalysis.get("positive_prob")) * 100f;
//                Float negative_prob = emotionalAnalysis.get("negative_prob") == null ? 0f : Float.parseFloat(emotionalAnalysis.get("negative_prob")) * 100f;
//                positiveProb = positive_prob.intValue();
//                negativeProb = negative_prob.intValue();
//            }
//            appraiseDO.setPositive(positiveProb);
//            appraiseDO.setNegative(negativeProb);
//            appraiseMapper.updateById(appraiseDO);
//            logger.info("评论内容 ： " + appraiseDO.getContent()
//                    + "评论积极率----" + appraiseDO.getPositive()
//                    + "评论消极率----" + appraiseDO.getNegative());
//            Thread.sleep(2000l);
//        }
//    }
//
//
//
//
//}
